/**
 * Copyright(c) by JNet Smartware Group.
 * All rights reserved. Not distribution or redistribution without
 * any permission of JNet Smartware Group.
 * 
 * @author thuc
 * 2010/08/07
 * Program: SWTReservationsEntry.java
 */
package vn.smartware.co.client.business;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

import vn.smartware.co.client.register.SWTRegisterCustomerEntry;
import vn.smartware.co.commons.Const;
import vn.smartware.co.commons.SWTUtils;
import vn.smartware.co.dto.BillDTO;
import vn.smartware.co.dto.MstCustomerDTO;
import vn.smartware.co.dto.MstDrinkDTO;
import vn.smartware.co.dto.MstFoodDTO;
import vn.smartware.co.dto.MstPriceDTO;
import vn.smartware.co.dto.MstRoomDTO;
import vn.smartware.co.dto.MstRoomPriceDTO;
import vn.smartware.co.dto.ReserveDetailDTO;
import vn.smartware.co.dto.ReserveDto;
import vn.smartware.co.forms.ReserveForm;
import vn.smartware.co.framework.common.BaseConstant;
import vn.smartware.co.framework.exception.ClientException;
import vn.smartware.co.framework.exception.FatalException;
import vn.smartware.co.framework.exception.ServerException;
import vn.smartware.co.framework.exception.SessionTimeOutException;
import vn.smartware.co.framework.form.CommonSearchForm;
import vn.smartware.co.framework.plugin.LangResources;
import vn.smartware.co.framework.swt.base.JNetComposite;
import vn.smartware.co.framework.swt.base.SWTManager;
import vn.smartware.co.framework.utils.MsgBoxUtils;
import vn.smartware.co.java.net.commons.Utils;

/**
 * SWTReservationsEntry
 * @author thuctt
 */
public class SWTReservationsEntry extends JNetComposite {

	private static Log log = LogFactory.getLog(SWTReservationsEntry.class);
	
	private Button btnSync1;

	private Button btnSync2;

	private Button btnSync3;
	
	private Text txtRoom;
	
	private Button btnNew;

	private Combo cmbMoney;

	private CLabel clblTotal;
	
	private CLabel clblRoomTotal;
	
	private CLabel clblOtherTotal;

	private CLabel clblDrinkTotal;

	private Button btnDrinkAdd;
	
	private Button btnTotal;

	private Text txtDrinkQty;

	private CLabel clblDrinkUnitPrice;

	private CLabel clblDrinkName;

	private Text txtDrinkNo;

	private Button btnDrinkRemove;

	private Table tblDrink;

	private Group grpDrink;

	private CLabel clblFoodTotal;

	private Button btnFoodAdd;

	private Text txtFoodQty;

	private CLabel clblFoodUnitPrice;

	private CLabel clblFoodName;

	private Group grpFood;

	private CLabel clblTel;

	private CLabel clblCusName;

	private Group grpCustomer;

	private CLabel clblRentPrice;

	private CLabel clblRoomName;

	private Button btnCustomerInput;

	private Group grpInfo;

	private CLabel clblMode;
	
	private Group grpSearch;

	private Button btnFoodRemove;

	private Text txtFoodNo;

	private Table tblFood;

	private CLabel clblRoomType;

	private CLabel clblMessage;
	
	private Button btnSave;

	private Button btnClear;

	private Combo cmbRentType;

	private Text txtNote;

	private CLabel clblIdNumber;

	private Button btnSearch;

	private Button btnEdit;

	private Button btnClose;

	private Button btnDelete;
	
	private Combo cmbRentStatus;
	
	private Group grpDetail;
	
	private static final String ID = "ID";
	
	private static final int TBL_ROW_COUNT = 3;
	
	private String mode;
	
	private ArrayList drinkList = null;
	
	private ArrayList foodList = null;
	
	private ReserveDto tmpReserveDto = null;
	
	private MstCustomerDTO tmpCustomer = null;
	
	private boolean saveFlg = false;
	private DateTime txtBookYmd;
	private DateTime txtBookTimer;
	private DateTime txtBeginYmd;
	private DateTime txtBeginTimer;
	private DateTime txtEndYmd;
	private DateTime txtEndTimer;
	
	/**
	 * Constructor.
	 * @param parent 
	 * @param style 
	 * @param prgName 
	 */
	public SWTReservationsEntry(Composite parent, int style, String prgName) {

		super(parent, style, prgName);

		try {
//			setBackground(BaseConstant.COLOR_BGR_BASE); 
//			executeInit();
			if (!initData()){
				lockScreen(true);
				btnClose.setEnabled(true);
				btnClose.setFocus();
				return;
			}
			clearAction();

		} catch (Exception e) {
			log.error("Exception.", e);
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * init data to display
	 * @throws FatalException
	 */
	@SuppressWarnings("unchecked")
	private boolean initData() throws FatalException {

//		try {
			Map map = new HashMap();
			map.put(Const.SYSTEM_CONFIG.RENT_TYPE, Boolean.FALSE);
			map.put(Const.SYSTEM_CONFIG.RESERVE_STATUS, Boolean.FALSE);
			map.put(Const.SYSTEM_CONFIG.MONEY_TYPE, Boolean.FALSE);
//			map = SWTUtils.ComboProcess.getComboInitItems(map, this);
			
			String[] items = (String[])map.get(Const.SYSTEM_CONFIG.RENT_TYPE);
			if (items == null || items.length == 0 || Utils.isNullEmpty(items[1])){
				MsgBoxUtils.errorMsgBox("errors.COMBO_DATA_NOT_SET", 
						new Object[]{LangResources.getText("SWTReservationsEntry.lblRentType")});
				return false;
			}
			cmbRentType.setItems(items);
			//
			items = (String[])map.get(Const.SYSTEM_CONFIG.RESERVE_STATUS);
			if (items == null || items.length == 0 || Utils.isNullEmpty(items[1])){
				MsgBoxUtils.errorMsgBox("errors.COMBO_DATA_NOT_SET", 
						new Object[]{LangResources.getText("SWTReservationsEntry.lblRentStatus")});
				return false;
			}
			cmbRentStatus.setItems(items);
			//
			items = (String[])map.get(Const.SYSTEM_CONFIG.MONEY_TYPE);
			if (items == null || items.length == 0 || Utils.isNullEmpty(items[1])){
				MsgBoxUtils.errorMsgBox("errors.COMBO_DATA_NOT_SET", 
						new Object[]{LangResources.getText("SWTReservationsEntry.cmbMoneyType")});
				return false;
			}
			cmbMoney.setItems(items);
		
//		} catch (SessionTimeOutException e) {
//			log.warn("SessionTimeOutException.", e);
//		}
		return true;
	}

	/**
	 * init controls
	 */
	protected void initialize() {

		grpSearch = new Group(this, SWT.NONE);
		grpSearch.setBounds(13, 5, 784, 57);
		grpSearch.setBackground(BaseConstant.COLOR_BGR_BASE);

		final CLabel lblRoomNo = new CLabel(grpSearch, SWT.CENTER | SWT.BORDER);
		lblRoomNo.setBounds(10, 20, 100, 22);
		lblRoomNo.setFont(BaseConstant.FONT_LINK_LABEL);
		lblRoomNo.setForeground(BaseConstant.COLOR_LINK_LABEL);
		lblRoomNo.setText(LangResources.getText("SWTReservationsEntry.lblRoom"));
		lblRoomNo.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		lblRoomNo.addMouseTrackListener(new MouseTrackAdapter() {
			Display display = Display.getCurrent();
			public void mouseEnter(MouseEvent e) {
				display.syncExec(new Runnable() {
					public void run() {
						lblRoomNo.setForeground(BaseConstant.COLOR_LINK_LABEL_MOUSE_ENTER);
					}
				});

			}
			public void mouseExit(MouseEvent arg0) {
				display.syncExec(new Runnable() {
					public void run() {
						lblRoomNo.setForeground(BaseConstant.COLOR_LINK_LABEL);
					}
				});
			}
		});
		lblRoomNo.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent arg0) {
				openRoomSearchScreen(txtRoom);
			}
		});

		txtRoom = new Text(grpSearch, SWT.BORDER | SWT.LEFT);
		txtRoom.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (Const.KEY_CODE_CTRL.equals(SWTUtils.KeyProcess.getKeyStateMask(e.stateMask))
						&& Const.KEY_CODE_F.equals(SWTUtils.KeyProcess.getKeyCode(e.keyCode))){
					
					openRoomSearchScreen(txtRoom);
				}
			}
		});
		txtRoom.setBounds(116, 20, 300, 22);
		txtRoom.setTextLimit(10);
		txtRoom.setFont(BaseConstant.FONT_BASE_TEXT);
		txtRoom.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		
		btnSearch = new Button(grpSearch, SWT.NONE);
		btnSearch.setBounds(422, 19,100, 23);
		btnSearch.setText(LangResources.getText("btnSearch"));
		btnSearch.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnSearch.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnSearch.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				searchAction();
			}
		});
		
		this.getShell().setDefaultButton(btnSearch);

		btnNew = new Button(grpSearch, SWT.NONE);
		btnNew.setBounds(528, 19, 100, 23);
		btnNew.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnNew.setText(LangResources.getText("btnNew"));
		btnNew.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnNew.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				if (Utils.isNullEmpty(txtRoom.getText())){
					newAction(null, true);
				} else {
					// get room
					MstRoomDTO room = getRoom();
					newAction(room, false);
				}
			}
		});

		clblMode = new CLabel(grpSearch, SWT.CENTER | SWT.SHADOW_IN | SWT.BORDER);
		clblMode.setBounds(660, 20, 100, 22);
		clblMode.setForeground(BaseConstant.COLOR_LINK_LABEL);
		clblMode.setFont(BaseConstant.FONT_BOLD_LABEL);
		clblMode.setBackground(BaseConstant.COLOR_BGR_LABEL);
		
		final Label line1 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
		line1.setBounds(0, 70, 812, 15);
		line1.setBackground(BaseConstant.COLOR_BGR_BASE);

		grpInfo = new Group(this, SWT.NONE);
		grpInfo.setBounds(13, 85, 784, 165);
		grpInfo.setBackground(BaseConstant.COLOR_BGR_BASE);

		final CLabel lblRoom = new CLabel(grpInfo, SWT.BORDER | SWT.CENTER);
		lblRoom.setBounds(10, 20,100, 22);
		lblRoom.setFont(BaseConstant.FONT_BASE_LABEL);
		lblRoom.setText(LangResources.getText("SWTReservationsEntry.lblRoom"));

		clblRoomName = new CLabel(grpInfo, SWT.SHADOW_IN | SWT.BORDER);
		clblRoomName.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblRoomName.setBackground(BaseConstant.COLOR_BGR_LABEL);
		clblRoomName.setBounds(116, 20, 302, 22);

		final CLabel lblRoomType = new CLabel(grpInfo, SWT.BORDER | SWT.CENTER);
		lblRoomType.setBounds(10, 48,100, 22);
		lblRoomType.setFont(BaseConstant.FONT_BASE_LABEL);
		lblRoomType.setText(LangResources.getText("SWTReservationsEntry.lblRoomType"));

		clblRoomType = new CLabel(grpInfo, SWT.SHADOW_IN | SWT.BORDER);
		clblRoomType.setBounds(116, 48,80, 22);
		clblRoomType.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblRoomType.setBackground(BaseConstant.COLOR_BGR_LABEL);

		cmbMoney = new Combo(grpInfo, SWT.READ_ONLY);
		cmbMoney.setBounds(338, 48, 80, 24);
		cmbMoney.setTextLimit(200);
		cmbMoney.setFont(BaseConstant.FONT_BASE_LABEL);
		cmbMoney.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		cmbMoney.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				clblMessage.setText("");
				ArrayList pricelist = (ArrayList)cmbRentType.getData();
				if (null != pricelist && !pricelist.isEmpty()){
					String price = getRoomPrice(pricelist, 
							SWTUtils.ComboProcess.getSelectingValue(cmbRentType),
							SWTUtils.ComboProcess.getSelectingValue(cmbMoney));
					clblRentPrice.setText(Utils.formatDouble(price));
				}
			}
		});

		final CLabel lblRentType = new CLabel(grpInfo, SWT.CENTER | SWT.BORDER);
		lblRentType.setBounds(10, 76, 100, 22);
		lblRentType.setFont(BaseConstant.FONT_BASE_LABEL);
		lblRentType.setText(LangResources.getText("SWTReservationsEntry.lblRentType"));

		cmbRentType = new Combo(grpInfo, SWT.READ_ONLY);
		cmbRentType.setBounds(116, 76,132, 24);
		cmbRentType.setFont(BaseConstant.FONT_BASE_TEXT);
		cmbRentType.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		cmbRentType.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				clblMessage.setText("");
				ArrayList pricelist = (ArrayList)cmbRentType.getData();
				if (null != pricelist && !pricelist.isEmpty()){
					String price = getRoomPrice(pricelist, 
							SWTUtils.ComboProcess.getSelectingValue(cmbRentType),
							SWTUtils.ComboProcess.getSelectingValue(cmbMoney));
					clblRentPrice.setText(Utils.formatDouble(price));
				}
			}
		});

		final CLabel lblRentPrice = new CLabel(grpInfo, SWT.CENTER | SWT.BORDER);
		lblRentPrice.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		lblRentPrice.setBounds(262, 76, 50, 22);
		lblRentPrice.setText(LangResources.getText("SWTReservationsEntry.lblRentPrice"));

		clblRentPrice = new CLabel(grpInfo, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblRentPrice.setBounds(318, 76, 100, 22);
		clblRentPrice.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblRentPrice.setBackground(BaseConstant.COLOR_BGR_LABEL);

		final CLabel lblRentStatus = new CLabel(grpInfo, SWT.CENTER | SWT.BORDER);
		lblRentStatus.setBounds(10, 127, 100, 22);
		lblRentStatus.setFont(BaseConstant.FONT_BASE_LABEL);
		lblRentStatus.setText(LangResources.getText("SWTReservationsEntry.lblRentStatus"));

		cmbRentStatus = new Combo(grpInfo, SWT.READ_ONLY);
		cmbRentStatus.setBounds(116, 127,132, 24);
		cmbRentStatus.setTextLimit(200);
		cmbRentStatus.setFont(BaseConstant.FONT_BASE_LABEL);
		cmbRentStatus.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);

		grpCustomer = new Group(grpInfo, SWT.NONE);
		grpCustomer.setText(LangResources.getText("SWTReservationsEntry.grpCustomer"));
		grpCustomer.setBounds(425, 10, 349, 107);
		grpCustomer.setBackground(BaseConstant.COLOR_BGR_BASE);

		final CLabel lblCustomer = new CLabel(grpCustomer, SWT.CENTER | SWT.BORDER);
		lblCustomer.setBounds(10, 18, 100, 22);
		lblCustomer.setFont(BaseConstant.FONT_LINK_LABEL);
		lblCustomer.setForeground(BaseConstant.COLOR_LINK_LABEL);
		lblCustomer.setText(LangResources.getText("SWTReservationsEntry.lblCustomer"));
		lblCustomer.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		lblCustomer.addMouseTrackListener(new MouseTrackAdapter() {
			Display display = Display.getCurrent();
			public void mouseEnter(MouseEvent e) {
				display.syncExec(new Runnable() {
					public void run() {
						lblCustomer.setForeground(BaseConstant.COLOR_LINK_LABEL_MOUSE_ENTER);
					}
				});

			}
			public void mouseExit(MouseEvent arg0) {
				display.syncExec(new Runnable() {
					public void run() {
						lblCustomer.setForeground(BaseConstant.COLOR_LINK_LABEL);
					}
				});
			}
		});
		lblCustomer.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent arg0) {
				openCustomerSearchScreen();
			}
		});

		clblCusName = new CLabel(grpCustomer, SWT.BORDER | SWT.LEFT);
		clblCusName.setBounds(116, 18, 223, 22);
		clblCusName.setFont(BaseConstant.FONT_BASE_LABEL);
		clblCusName.setBackground(BaseConstant.COLOR_BGR_LABEL);
		clblCusName.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (Const.KEY_CODE_CTRL.equals(SWTUtils.KeyProcess.getKeyStateMask(e.stateMask))
						&& Const.KEY_CODE_F.equals(SWTUtils.KeyProcess.getKeyCode(e.keyCode))){
					
					openCustomerSearchScreen();
				}
			}
		});

		final CLabel lblIdentify = new CLabel(grpCustomer, SWT.CENTER | SWT.BORDER);
		lblIdentify.setBounds(10, 46, 100, 22);
		lblIdentify.setFont(BaseConstant.FONT_BASE_LABEL);
		lblIdentify.setText(LangResources.getText("SWTReservationsEntry.lblIdentify"));

		clblIdNumber = new CLabel(grpCustomer, SWT.BORDER);
		clblIdNumber.setBounds(116, 46,100, 22);
		clblIdNumber.setFont(BaseConstant.FONT_BASE_LABEL);
		clblIdNumber.setBackground(BaseConstant.COLOR_BGR_LABEL);

		final CLabel lblPhone = new CLabel(grpCustomer, SWT.CENTER | SWT.BORDER);
		lblPhone.setBounds(10, 74, 100, 22);
		lblPhone.setFont(BaseConstant.FONT_BASE_LABEL);
		lblPhone.setText(LangResources.getText("SWTReservationsEntry.lblPhone"));

		clblTel = new CLabel(grpCustomer, SWT.BORDER);
		clblTel.setBounds(116, 74, 100, 22);
		clblTel.setFont(BaseConstant.FONT_BASE_LABEL);
		clblTel.setBackground(BaseConstant.COLOR_BGR_LABEL);

		btnCustomerInput = new Button(grpCustomer, SWT.NONE);
		btnCustomerInput.setBounds(239, 73,100, 23);
		btnCustomerInput.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnCustomerInput.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnCustomerInput.setText(LangResources.getText("SWTReservationsEntry.btnCustomerInput"));
		btnCustomerInput.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				callCustomerInputEntry();
			}
		});
		
		btnEdit = new Button(grpInfo, SWT.NONE);
		btnEdit.setBounds(262, 126,100, 23);
		btnEdit.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnEdit.setText(LangResources.getText("btnEdit"));
		btnEdit.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnEdit.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				editAction();
			}
		});
		
		final Label line2 = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR);
		line2.setBounds(0, 256, 812, 15);
		line2.setBackground(BaseConstant.COLOR_BGR_BASE);
		
		grpDetail = new Group(this, SWT.NONE);
		grpDetail.setSize(782, 339);
		grpDetail.setLocation(15, 273);
		grpDetail.setBackground(BaseConstant.COLOR_BGR_BASE);

		final CLabel lblBookTime = new CLabel(grpDetail, SWT.CENTER | SWT.BORDER);
		lblBookTime.setBounds(10, 20, 100, 22);
		lblBookTime.setFont(BaseConstant.FONT_BASE_LABEL);
		lblBookTime.setText(LangResources.getText("SWTReservationsEntry.lblBookTime"));
		
		this.txtBookYmd = new DateTime(this.grpDetail, SWT.BORDER | SWT.DROP_DOWN);
		txtBookYmd.setEnabled(false);
		this.txtBookYmd.setBounds(116, 19, 78, 24);
		this.txtBookYmd.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		
		this.txtBookTimer = new DateTime(this.grpDetail, SWT.BORDER | SWT.TIME | SWT.SHORT);
		txtBookTimer.setEnabled(false);
		this.txtBookTimer.setBounds(195, 19, 49, 24);
		this.txtBookTimer.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);

		btnSync1 = new Button(grpDetail, SWT.NONE);
		btnSync1.setBounds(247, 20, 40, 23);
		btnSync1.setImage(SWTResourceManager.getImage(SWTReservationsEntry.class, BaseConstant.IMG_SYNC_ICON));
		btnSync1.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnSync1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Calendar cal = Calendar.getInstance();
				txtBookYmd.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
				txtBookTimer.setTime(cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
			}
		});
		
		final CLabel lblActiveTime = new CLabel(grpDetail, SWT.CENTER | SWT.BORDER);
		lblActiveTime.setBounds(10, 48, 100, 22);
		lblActiveTime.setFont(BaseConstant.FONT_BASE_LABEL);
		lblActiveTime.setText(LangResources.getText("SWTReservationsEntry.lblActiveTime"));
		
		txtBeginYmd = new DateTime(grpDetail, SWT.BORDER | SWT.DROP_DOWN);
		txtBeginYmd.setEnabled(false);
		txtBeginYmd.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtBeginYmd.setBounds(116, 47, 78, 24);
		
		txtBeginTimer = new DateTime(grpDetail, SWT.BORDER | SWT.TIME | SWT.SHORT);
		txtBeginTimer.setEnabled(false);
		txtBeginTimer.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtBeginTimer.setBounds(195, 47, 49, 24);
		
		btnSync2 = new Button(grpDetail, SWT.NONE);
		btnSync2.setBounds(247, 48, 40, 23);
		btnSync2.setImage(SWTResourceManager.getImage(SWTReservationsEntry.class, BaseConstant.IMG_SYNC_ICON));
		btnSync2.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnSync2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Calendar cal = Calendar.getInstance();
				txtBeginYmd.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
				txtBeginTimer.setTime(cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
			}
		});

		final CLabel lblFinishTime = new CLabel(grpDetail, SWT.CENTER | SWT.BORDER);
		lblFinishTime.setBounds(10, 76, 100, 22);
		lblFinishTime.setFont(BaseConstant.FONT_BASE_LABEL);
		lblFinishTime.setText(LangResources.getText("SWTReservationsEntry.lblFinishTime"));
		
		txtEndYmd = new DateTime(grpDetail, SWT.BORDER | SWT.DROP_DOWN);
		txtEndYmd.setEnabled(false);
		txtEndYmd.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtEndYmd.setBounds(116, 75, 78, 24);
		
		txtEndTimer = new DateTime(grpDetail, SWT.BORDER | SWT.TIME | SWT.SHORT);
		txtEndTimer.setEnabled(false);
		txtEndTimer.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtEndTimer.setBounds(195, 75, 49, 24);
		
		btnSync3 = new Button(grpDetail, SWT.NONE);
		btnSync3.setBounds(247, 76, 40, 23);
		btnSync3.setImage(SWTResourceManager.getImage(SWTReservationsEntry.class, BaseConstant.IMG_SYNC_ICON));
		btnSync3.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnSync3.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Calendar cal = Calendar.getInstance();
				txtEndYmd.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
				txtEndTimer.setTime(cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
			}
		});

		final CLabel lblNote = new CLabel(grpDetail, SWT.BORDER | SWT.CENTER);
		lblNote.setBounds(294, 20, 100, 22);
		lblNote.setFont(BaseConstant.FONT_BASE_LABEL);
		lblNote.setText(LangResources.getText("SWTReservationsEntry.lblNote"));

		txtNote = new Text(grpDetail, SWT.BORDER);
		txtNote.setBounds(400, 20, 360, 78);
		txtNote.setTextLimit(100);
		txtNote.setFont(BaseConstant.FONT_BASE_TEXT);
		txtNote.setBackground(BaseConstant.COLOR_TEXT_NORMAL);

		grpFood = new Group(grpDetail, SWT.NONE);
		grpFood.setBounds(10, 105, 370, 175);
		grpFood.setText(LangResources.getText("SWTReservationsEntry.grpFood"));
		grpFood.setBackground(BaseConstant.COLOR_BGR_BASE);

		tblFood = new Table(grpFood, SWT.FULL_SELECTION | SWT.BORDER);
		tblFood.setBounds(10, 49,350, 90);
		tblFood.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent arg0) {
				clblMessage.setText("");
				editSelectingDetail(tblFood, ReserveForm.FOOD);
			}
		});
		tblFood.setFont(BaseConstant.FONT_BASE_LABEL);
		tblFood.setData(BaseConstant.TABLE_ROW_COUNT, Integer.toString(TBL_ROW_COUNT));
		tblFood.setLinesVisible(true);
		tblFood.setHeaderVisible(true);

		final TableColumn tcolFood = new TableColumn(tblFood, SWT.NONE);
		tcolFood.setWidth(110);
		tcolFood.setText(LangResources.getText("SWTReservationsEntry.tblFood.tcolFood")); 
		
		final TableColumn tcolFoodUnitPrice = new TableColumn(tblFood, SWT.RIGHT);
		tcolFoodUnitPrice.setWidth(72);
		tcolFoodUnitPrice.setText(LangResources.getText("SWTReservationsEntry.tblFood.tcolFoodUnitPrice"));
		
		final TableColumn tcolFoodQty = new TableColumn(tblFood, SWT.RIGHT);
		tcolFoodQty.setWidth(68);
		tcolFoodQty.setText(LangResources.getText("SWTReservationsEntry.tblFood.tcolFoodQty"));
		
		final TableColumn tcolFoodPrice = new TableColumn(tblFood, SWT.RIGHT);
		tcolFoodPrice.setWidth(77);
		tcolFoodPrice.setText(LangResources.getText("SWTReservationsEntry.tblFood.tcolFoodPrice"));

		final CLabel lblFoodNo = new CLabel(grpFood, SWT.BORDER | SWT.CENTER);
		lblFoodNo.setBounds(10, 145,24, 22);
		lblFoodNo.setFont(BaseConstant.FONT_LINK_LABEL);
		lblFoodNo.setForeground(BaseConstant.COLOR_LINK_LABEL);
		lblFoodNo.setText(LangResources.getText("SWTReservationsEntry.lblFoodNo"));
		lblFoodNo.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		lblFoodNo.addMouseTrackListener(new MouseTrackAdapter() {
			Display display = Display.getCurrent();
			public void mouseEnter(MouseEvent e) {
				display.syncExec(new Runnable() {
					public void run() {
						lblFoodNo.setForeground(BaseConstant.COLOR_LINK_LABEL_MOUSE_ENTER);
					}
				});

			}
			public void mouseExit(MouseEvent arg0) {
				display.syncExec(new Runnable() {
					public void run() {
						lblFoodNo.setForeground(BaseConstant.COLOR_LINK_LABEL);
					}
				});
			}
		});
		lblFoodNo.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent arg0) {
				openDetailSearchScreen(txtFoodNo, clblFoodName, clblFoodUnitPrice, ReserveForm.FOOD);
			}
		});

		txtFoodNo = new Text(grpFood, SWT.RIGHT | SWT.BORDER);
		txtFoodNo.setBounds(34, 145,28, 22);
		txtFoodNo.addFocusListener(new FocusAdapter() {
			public void focusGained(final FocusEvent arg0) {
				clblMessage.setText("");
			}
			public void focusLost(final FocusEvent arg0) {
				detailNoLostFocus(txtFoodNo, clblFoodName, clblFoodUnitPrice, ReserveForm.FOOD);
			}
		});
		txtFoodNo.setTextLimit(3);
		txtFoodNo.setFont(BaseConstant.FONT_BASE_TEXT);
		txtFoodNo.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtFoodNo.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (Const.KEY_CODE_CTRL.equals(SWTUtils.KeyProcess.getKeyStateMask(e.stateMask))
						&& Const.KEY_CODE_F.equals(SWTUtils.KeyProcess.getKeyCode(e.keyCode))){
					
					openDetailSearchScreen(txtFoodNo, clblFoodName, clblFoodUnitPrice, ReserveForm.FOOD);
				}
			}
		});

		clblFoodName = new CLabel(grpFood, SWT.SHADOW_IN | SWT.BORDER);
		clblFoodName.setBounds(62, 145, 83, 22);
		clblFoodName.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblFoodName.setBackground(BaseConstant.COLOR_BGR_LABEL);

		clblFoodUnitPrice = new CLabel(grpFood, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblFoodUnitPrice.setBounds(145, 145, 80, 22);
		clblFoodUnitPrice.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblFoodUnitPrice.setBackground(BaseConstant.COLOR_BGR_LABEL);

		txtFoodQty = new Text(grpFood, SWT.BORDER | SWT.RIGHT);
		txtFoodQty.setBounds(225, 145, 63, 22);
		txtFoodQty.setTextLimit(3);
		txtFoodQty.setFont(BaseConstant.FONT_BASE_TEXT);
		txtFoodQty.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);

		btnFoodAdd = new Button(grpFood, SWT.NONE);
		btnFoodAdd.setBounds(294, 145, 66, 23);
		btnFoodAdd.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnFoodAdd.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnFoodAdd.setText(LangResources.getText("SWTReservationsEntry.btnAdd"));
		btnFoodAdd.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				addFoodDetail();
			}
		});

		btnFoodRemove = new Button(grpFood, SWT.NONE);
		btnFoodRemove.setBounds(10, 20,100, 23);
		btnFoodRemove.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnFoodRemove.setText(LangResources.getText("SWTReservationsEntry.btnRemove"));
		btnFoodRemove.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnFoodRemove.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				removeDetail(tblFood, ReserveForm.FOOD);
			}
		});

		final Label lblPriceTotal = new Label(grpFood, SWT.CENTER);
		lblPriceTotal.setBounds(225, 23, 45, 18);
		lblPriceTotal.setFont(BaseConstant.FONT_BASE_LABEL);
		lblPriceTotal.setBackground(BaseConstant.COLOR_BGR_BASE);
		lblPriceTotal.setText(LangResources.getText("SWTReservationsEntry.lblTotal"));

		clblFoodTotal = new CLabel(grpFood, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblFoodTotal.setBounds(286, 20, 74, 22);
		clblFoodTotal.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblFoodTotal.setBackground(BaseConstant.COLOR_BGR_LABEL);

		grpDrink = new Group(grpDetail, SWT.NONE);
		grpDrink.setBounds(401, 105, 370, 175);
		grpDrink.setText(LangResources.getText("SWTReservationsEntry.grpDrink"));
		grpDrink.setBackground(BaseConstant.COLOR_BGR_BASE);

		tblDrink = new Table(grpDrink, SWT.FULL_SELECTION | SWT.BORDER);
		tblDrink.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent arg0) {
				clblMessage.setText("");
				editSelectingDetail(tblDrink, ReserveForm.DRINK);
			}
		});
		tblDrink.setFont(BaseConstant.FONT_BASE_LABEL);
		tblDrink.setData(BaseConstant.TABLE_ROW_COUNT, Integer.toString(TBL_ROW_COUNT));
		tblDrink.setBounds(10, 49, 350, 90);
		tblDrink.setLinesVisible(true);
		tblDrink.setHeaderVisible(true);

		final TableColumn tcolDrink = new TableColumn(tblDrink, SWT.NONE);
		tcolDrink.setWidth(110);
		tcolDrink.setText(LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrink"));

		final TableColumn tcolDrinkUnitPrice = new TableColumn(tblDrink, SWT.RIGHT);
		tcolDrinkUnitPrice.setWidth(72);
		tcolDrinkUnitPrice.setText(LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrinkUnitPrice"));

		final TableColumn tcolDrinkQty = new TableColumn(tblDrink, SWT.RIGHT);
		tcolDrinkQty.setWidth(68);
		tcolDrinkQty.setText(LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrinkQty"));

		final TableColumn tcolDrinkPrice = new TableColumn(tblDrink, SWT.RIGHT);
		tcolDrinkPrice.setWidth(77);
		tcolDrinkPrice.setText(LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrinkPrice"));

		final CLabel lblDrinkNo = new CLabel(grpDrink, SWT.CENTER | SWT.BORDER);
		lblDrinkNo.setFont(BaseConstant.FONT_LINK_LABEL);
		lblDrinkNo.setBounds(10, 145, 24, 22);
		lblDrinkNo.setForeground(BaseConstant.COLOR_LINK_LABEL);
		lblDrinkNo.setText(LangResources.getText("SWTReservationsEntry.lblDrinkNo"));
		lblDrinkNo.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		lblDrinkNo.addMouseTrackListener(new MouseTrackAdapter() {
			Display display = Display.getCurrent();
			public void mouseEnter(MouseEvent e) {
				display.syncExec(new Runnable() {
					public void run() {
						lblDrinkNo.setForeground(BaseConstant.COLOR_LINK_LABEL_MOUSE_ENTER);
					}
				});

			}
			public void mouseExit(MouseEvent arg0) {
				display.syncExec(new Runnable() {
					public void run() {
						lblDrinkNo.setForeground(BaseConstant.COLOR_LINK_LABEL);
					}
				});
			}
		});
		lblDrinkNo.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent arg0) {
				openDetailSearchScreen(txtDrinkNo, clblDrinkName, clblDrinkUnitPrice, ReserveForm.DRINK);
			}
		});

		txtDrinkNo = new Text(grpDrink, SWT.BORDER | SWT.RIGHT);
		txtDrinkNo.addFocusListener(new FocusAdapter() {
			public void focusGained(final FocusEvent arg0) {
				clblMessage.setText("");
			}
			public void focusLost(final FocusEvent arg0) {
				detailNoLostFocus(txtDrinkNo, clblDrinkName, clblDrinkUnitPrice, ReserveForm.DRINK);
			}
		});
		txtDrinkNo.setTextLimit(3);
		txtDrinkNo.setFont(BaseConstant.FONT_BASE_TEXT);
		txtDrinkNo.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtDrinkNo.setBounds(34, 145, 28, 22);
		txtDrinkNo.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (Const.KEY_CODE_CTRL.equals(SWTUtils.KeyProcess.getKeyStateMask(e.stateMask))
						&& Const.KEY_CODE_F.equals(SWTUtils.KeyProcess.getKeyCode(e.keyCode))){
					
					openDetailSearchScreen(txtDrinkNo, clblDrinkName, clblDrinkUnitPrice, ReserveForm.DRINK);
				}
			}
		});

		clblDrinkName = new CLabel(grpDrink, SWT.SHADOW_IN | SWT.BORDER);
		clblDrinkName.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblDrinkName.setBackground(BaseConstant.COLOR_BGR_LABEL);
		clblDrinkName.setBounds(62, 145, 83, 22);

		clblDrinkUnitPrice = new CLabel(grpDrink, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblDrinkUnitPrice.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblDrinkUnitPrice.setBackground(BaseConstant.COLOR_BGR_LABEL);
		clblDrinkUnitPrice.setBounds(145, 145, 80, 22);

		txtDrinkQty = new Text(grpDrink, SWT.BORDER | SWT.RIGHT);
		txtDrinkQty.setTextLimit(3);
		txtDrinkQty.setFont(BaseConstant.FONT_BASE_TEXT);
		txtDrinkQty.setBackground(BaseConstant.COLOR_TEXT_REQUIRED);
		txtDrinkQty.setBounds(225, 145, 63, 22);

		btnDrinkAdd = new Button(grpDrink, SWT.NONE);
		btnDrinkAdd.setBounds(294, 145, 66, 23);
		btnDrinkAdd.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnDrinkAdd.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnDrinkAdd.setText(LangResources.getText("SWTReservationsEntry.btnAdd"));
		btnDrinkAdd.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				addDrinkDetail();
			}
		});

		btnDrinkRemove = new Button(grpDrink, SWT.NONE);
		btnDrinkRemove.setBounds(10, 20, 100, 23);
		btnDrinkRemove.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnDrinkRemove.setText(LangResources.getText("SWTReservationsEntry.btnRemove"));
		btnDrinkRemove.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnDrinkRemove.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				removeDetail(tblDrink, ReserveForm.DRINK);
			}
		});

		final Label lblPriceTotal_1 = new Label(grpDrink, SWT.CENTER);
		lblPriceTotal_1.setBounds(225, 23, 45, 18);
		lblPriceTotal_1.setFont(BaseConstant.FONT_BASE_LABEL);
		lblPriceTotal_1.setBackground(BaseConstant.COLOR_BGR_BASE);
		lblPriceTotal_1.setText(LangResources.getText("SWTReservationsEntry.lblTotal"));

		clblDrinkTotal = new CLabel(grpDrink, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblDrinkTotal.setBounds(286, 20, 74, 22);
		clblDrinkTotal.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblDrinkTotal.setBackground(BaseConstant.COLOR_BGR_LABEL);

		final Group grpBill = new Group(grpDetail, SWT.NONE);
		grpBill.setBounds(10, 285, 760, 45);
		grpBill.setBackground(BaseConstant.COLOR_BGR_BASE);
		grpBill.setText(LangResources.getText("SWTReservationsEntry.grpBill"));
		
		final CLabel lblRoomPrice = new CLabel(grpBill, SWT.CENTER | SWT.BORDER);
		lblRoomPrice.setBounds(10, 15, 100, 22);
		lblRoomPrice.setFont(BaseConstant.FONT_BASE_LABEL);
		lblRoomPrice.setText(LangResources.getText("SWTReservationsEntry.lblRoomPrice"));

		clblRoomTotal = new CLabel(grpBill, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblRoomTotal.setBounds(116, 15, 100, 22);
		clblRoomTotal.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblRoomTotal.setBackground(BaseConstant.COLOR_BGR_LABEL);
		
		final CLabel lblOtherPrice = new CLabel(grpBill, SWT.CENTER | SWT.BORDER);
		lblOtherPrice.setBounds(222, 15, 100, 22);
		lblOtherPrice.setFont(BaseConstant.FONT_BASE_LABEL);
		lblOtherPrice.setText(LangResources.getText("SWTReservationsEntry.lblOtherPrice"));

		clblOtherTotal = new CLabel(grpBill, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblOtherTotal.setBounds(328, 15, 100, 22);
		clblOtherTotal.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblOtherTotal.setBackground(BaseConstant.COLOR_BGR_LABEL);
		
		final CLabel lblTotal = new CLabel(grpBill, SWT.CENTER | SWT.BORDER);
		lblTotal.setBounds(434, 15, 100, 22);
		lblTotal.setFont(BaseConstant.FONT_BASE_LABEL);
		lblTotal.setText(LangResources.getText("SWTReservationsEntry.lblTotal"));

		clblTotal = new CLabel(grpBill, SWT.SHADOW_IN | SWT.BORDER | SWT.RIGHT);
		clblTotal.setBounds(540, 15, 100, 22);
		clblTotal.setFont(BaseConstant.FONT_BASE_LABEL_NAME);
		clblTotal.setBackground(BaseConstant.COLOR_BGR_LABEL);
		
		btnTotal = new Button(grpBill, SWT.NONE);
		btnTotal.setBounds(646, 15, 100, 23);
		btnTotal.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnTotal.setText(LangResources.getText("SWTReservationsEntry.btnTotal"));
		btnTotal.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnTotal.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				calTotalPrice();
			}
		});

		final Label line3 = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR);
		line3.setBounds(0, 618, 812, 15);
		line3.setBackground(BaseConstant.COLOR_BGR_BASE);
		
		btnDelete = new Button(this, SWT.NONE);
		btnDelete.setBounds(379, 637,100, 23);
		btnDelete.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnDelete.setText(LangResources.getText("btnDelete"));
		btnDelete.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnDelete.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				deleteAction();
			}
		});

		btnSave = new Button(this, SWT.NONE);
		btnSave.setBounds(485, 637, 100, 23);
		btnSave.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnSave.setText(LangResources.getText("btnSave"));
		btnSave.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnSave.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				saveAction();
			}
		});

		btnClear = new Button(this, SWT.NONE);
		btnClear.setBounds(591, 637, 100, 23);
		btnClear.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnClear.setText(LangResources.getText("btnClear"));
		btnClear.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnClear.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				clearAction();
			}
		});

		btnClose = new Button(this, SWT.NONE);
		btnClose.setBounds(697, 637, 100, 23);
		btnClose.setFont(BaseConstant.FONT_BASE_BUTTON);
		btnClose.setText(LangResources.getText("btnClose"));
		btnClose.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		btnClose.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				if (!closeAction()){
					btnClose.setFocus();
				}
			}
		});

		clblMessage = new CLabel(this, SWT.SHADOW_IN | SWT.CENTER | SWT.BORDER);
		clblMessage.setBounds(15, 635, 250, 25);
		clblMessage.setForeground(BaseConstant.COLOR_LINK_LABEL);
		clblMessage.setFont(BaseConstant.FONT_BOLD_LABEL);
		clblMessage.setBackground(BaseConstant.COLOR_BGR_LABEL);
	}

	/**
	 * clearAction
	 */
	protected void clearAction() {
		
		SWTUtils.OperatorUI.clearAll(this.getChildren());
		//
		SWTUtils.OperatorUI.setEnableAll(grpSearch.getChildren(), true);
		SWTUtils.OperatorUI.setEnableAll(grpInfo.getChildren(), false);
		SWTUtils.OperatorUI.setEnableAll(grpDetail.getChildren(), false);
		Control[] grpButton = new Control[]{
				btnDelete,
				btnSave,
		};
		SWTUtils.OperatorUI.setEnableAll(grpButton, false);
		txtRoom.setFocus();
		//
		this.tmpReserveDto = null;
		this.drinkList = null;
		this.foodList = null;
		this.mode = null;
		this.tmpCustomer = null;
		this.saveFlg = false;
	}

	/**
	 * deleteAction
	 */
	protected void deleteAction() {
		
		try {
			clblMessage.setText("");
			
			if (MsgBoxUtils.questionMsgBox("question.BE_SURE") == SWT.NO){
				btnDelete.setFocus();
				return;
			}
			
			ReserveForm form = new ReserveForm();
			form.setReserveDto(tmpReserveDto);
			form.setProcessMode(Const.MODE_DEL);
			form.setActionForm("reserveForm");
			form.setActionMethod("saveAction");
			form = (ReserveForm)execute(form);
			
			//release resource
			this.tmpReserveDto = null;
			this.drinkList = null;
			this.foodList = null;
			this.mode = null;
			this.tmpCustomer = null;
			this.saveFlg = false;
			
			SWTUtils.OperatorUI.setEnableAll(grpSearch.getChildren(), true);
			SWTUtils.OperatorUI.setEnableAll(grpInfo.getChildren(), false);
			SWTUtils.OperatorUI.setEnableAll(grpDetail.getChildren(), false);
			SWTUtils.OperatorUI.setEnableAll(new Control[]{btnDelete, btnSave}, false);
			txtRoom.setFocus();
			
			MsgBoxUtils.setStatusLabelMessage(clblMessage, "info.DELETE_SUCCESSFUL");
			
		}catch (ClientException e) {
			log.error("ClientException", e);
		}catch (FatalException e) {
			log.error("FatalException.", e);
			fatalErrorMsgBox();
		}
	}

	/**
	 * displayAction
	 */
	protected void searchAction() {
		
		try {
			clblMessage.setText("");
			SWTUtils.OperatorUI.clearAll(grpInfo.getChildren());
			SWTUtils.OperatorUI.clearAll(grpDetail.getChildren());
			
			// if reserve no is empty
			if (Utils.isNullEmpty(txtRoom.getText())){
				int ans = MsgBoxUtils.questionMsgBox("question.CREATE_NEW", 
						new Object[]{LangResources.getText("SWTReservationsEntry.lblRoom")});
				
				if (ans == SWT.NO){
					txtRoom.setFocus();
					return;
				}
				newAction(null, true);
				return;
			}
			
			// get room
			CommonSearchForm form = new CommonSearchForm();
			form.setActionForm("commonSearchForm");
			form.setActionMethod("getRoomList");
			form.setSearchName(Utils.toEmpty(txtRoom.getText()));
			
			form = (CommonSearchForm)execute(form);
			
			MstRoomDTO room = null;
			ArrayList roomList = form.getList();
			if (roomList.size() > 1){
				room = SWTUtils.SWTControlProcess.openRoomSearchScreen(txtRoom, true);
				
			}else if (roomList != null && roomList.size() == 1){
				room = (MstRoomDTO)roomList.get(0);
			}
			
			if (null == room){
				return;
			}
			
			//Search action
			ReserveForm searchform = new ReserveForm();
			searchform.setActionForm("reserveForm");
			searchform.setActionMethod("getReserveInfo");
			
			searchform.getReserveDto().setRoom(room);
			
			searchform = (ReserveForm)execute(searchform);
			
			if (Utils.isNullEmpty(searchform.getReserveDto().getReserveId())){
				int ans = MsgBoxUtils.questionMsgBox("question.CREATE_NEW_IF_NO_DATA_FOUND");
				
				if (ans == SWT.NO){
					txtRoom.setFocus();
					return;
				}
				newAction(room, false);
				return;
			}
			
			tmpReserveDto = searchform.getReserveDto();
			displayReserveInfo();
			
			cmbRentType.setFocus();
			
		} catch (SessionTimeOutException e) {
			log.error("SessionTimeOutException", e);
		} catch (ServerException e) {
			log.error("ServerException.", e);
			fatalErrorMsgBox();
		} catch (FatalException e) {
			log.error("FatalException.", e);
			fatalErrorMsgBox();
		}
	}

	/**
	 * displayReserveInfo
	 */
	private void displayReserveInfo() {

		if (null == tmpReserveDto){
			return;
		}
		
		SWTUtils.ComboProcess.setDisplayLabel(cmbRentType, tmpReserveDto.getRentType());
		if (!Utils.isNullEmpty(tmpReserveDto.getFinishYmd())
				&& !Utils.isNullEmpty(tmpReserveDto.getFinishTime())){
			SWTUtils.ComboProcess.setDisplayLabel(cmbRentStatus, Const.SYSTEM_CONFIG.RESERVE_STATUS_FINISHED);
		} else if (!Utils.isNullEmpty(tmpReserveDto.getInuseYmd())
				&& !Utils.isNullEmpty(tmpReserveDto.getInuseTime())){
			SWTUtils.ComboProcess.setDisplayLabel(cmbRentStatus, Const.SYSTEM_CONFIG.RESERVE_STATUS_IN_USE);
		} else {
			SWTUtils.ComboProcess.setDisplayLabel(cmbRentStatus, Const.SYSTEM_CONFIG.RESERVE_STATUS_BOOKING);
		}
		SWTUtils.ComboProcess.setDisplayLabel(cmbMoney, tmpReserveDto.getCurrency());
		// set room info
		MstRoomDTO room = tmpReserveDto.getRoom();
		if (room != null){
			clblRoomName.setText(room.getRoomName());
			clblRoomName.setData(room.getRoomNo());
			clblRoomType.setText(room.getRoomTypeName());
			cmbRentType.setData(room.getPriceList());
			String price = getRoomPrice(room.getPriceList(), 
					SWTUtils.ComboProcess.getSelectingValue(cmbRentType),
					SWTUtils.ComboProcess.getSelectingValue(cmbMoney));
			clblRentPrice.setText(Utils.formatDouble(price));
		}
		// set customer info
		tmpCustomer = tmpReserveDto.getCustomer();
		if (tmpCustomer != null){
			clblCusName.setText(tmpCustomer.getName());
			clblIdNumber.setText(tmpCustomer.getIdNumber());
			clblTel.setText(tmpCustomer.getTel());
		}
		//
		displayReserveDetail();
		// control screen after searching
		SWTUtils.OperatorUI.setEnableAll(grpSearch.getChildren(), false);
		SWTUtils.OperatorUI.setEnableAll(grpInfo.getChildren(), true);
		SWTUtils.OperatorUI.setEnableAll(new Control[]{grpDetail, cmbMoney}, false);
		Control[] grpButton = new Control[]{
				btnDelete,
				btnSave,
		};
		SWTUtils.OperatorUI.setEnableAll(grpButton, true);
		clblMode.setText(Const.MODE_EDIT);
		this.mode = Const.MODE_EDIT;
	}

	/**
	 * displayReserveDetail
	 *
	 */
	private void displayReserveDetail() {

//		txtBookYmd.setText(tmpReserveDto.getBookingYmd());
//		txtBookYmd.setText(tmpReserveDto.getBookingTime());
//		txtBeginYmd.setText(tmpReserveDto.getInuseYmd());
//		txtBeginTimer.setText(tmpReserveDto.getInuseTime());
//		txtFinishTimer.setText(tmpReserveDto.getFinishTime());
//		txtFinishYmd.setText(tmpReserveDto.getFinishYmd());
		txtNote.setText(tmpReserveDto.getNote());
		//set data table food and drink
		this.drinkList = (ArrayList)tmpReserveDto.getDrinkList().clone();
		this.foodList = (ArrayList)tmpReserveDto.getFoodList().clone();
		displayTableDetail(tblDrink, drinkList, clblDrinkTotal);
		displayTableDetail(tblFood, foodList, clblFoodTotal);
		//
		if (!Utils.isNullEmpty(tmpReserveDto.getFinishYmd()) 
				&& !Utils.isNullEmpty(tmpReserveDto.getFinishTime())){
			BillDTO bill = tmpReserveDto.getBill();
			if (null != bill){
				clblTotal.setText(Utils.formatDouble(bill.getPayMoney()));
			}else{
				clblTotal.setText("");
			}
			double roomtotal = SWTUtils.SWTControlProcess.calRoomTotalMoney(tmpReserveDto, clblRentPrice.getText());
			double othertotal = calOthersTotalMoney(tmpReserveDto.getRentType());
			clblRoomTotal.setText(Utils.formatDouble(String.valueOf(Utils.round(roomtotal, 1))));
			clblOtherTotal.setText(Utils.formatDouble(String.valueOf(Utils.round(othertotal, 1))));
		}
	}

	/**
	 * displayTableDetail
	 * @param table
	 * @param list
	 * @param clblTotal 
	 */
	private void displayTableDetail(Table table, ArrayList list, CLabel clblTotal) {

		table.removeAll();
		
		int rowcount = TBL_ROW_COUNT;
		if (list != null && list.size() >= rowcount){
			rowcount = list.size() + 2;
		}
		long total = 0;
		for (int i = 0; i < rowcount; i++) {
			TableItem tblItem = new TableItem(table, SWT.NONE);
			
			if (list != null && i < list.size()){
				ReserveDetailDTO detail = (ReserveDetailDTO)list.get(i);
				
				String[] items = new String[table.getColumnCount()];
				int idx = 0;
				
				items[idx++] = detail.getDetailname();
				String unitPrice = "0";
				if (!Utils.isNullEmpty(detail.getUnitPrice())){
					unitPrice = detail.getUnitPrice();
				}
				items[idx++] = Utils.formatDouble(unitPrice);
				String qty = "0";
				if (!Utils.isNullEmpty(detail.getQuantity())){
					qty = detail.getQuantity();
				}
				items[idx++] = qty;
				double price = Double.parseDouble(unitPrice) * Integer.parseInt(qty);
				items[idx++] = Utils.formatDouble(String.valueOf(price));
				total += price;
				
				tblItem.setText(items);
				tblItem.setData(detail);
				tblItem.setData(ID, detail.getDetailNo());
			}
			
			if (i%2 == 0){
				tblItem.setBackground(BaseConstant.COLOR_TABLE_ROW_EVEN);
			}
		}
		table.setData(list);
		
		if (null != list && !list.isEmpty()){
			clblTotal.setText(Utils.formatDouble(String.valueOf(total)));
		} else {
			clblTotal.setText("");
		}
	}

	/**
	 * getRoomPrice
	 * @param priceList
	 * @param rentType
	 * @param currency 
	 * @return String
	 */
	private String getRoomPrice(ArrayList priceList, String rentType, String currency) {
		
		for (int i = 0; i < priceList.size(); i++) {
			MstRoomPriceDTO priceDto = (MstRoomPriceDTO)priceList.get(i);
			if (priceDto.getMoneyType().equals(currency)
					&& priceDto.getRentType().equals(rentType)){
				return priceDto.getPrice();
			}
		}
		return "";
	}

	/**
	 * editAction
	 */
	protected void editAction() {
		
		try {
			clblMessage.setText("");
			
			if (!chkInput()){
				SWTUtils.OperatorUI.setEnableAll(grpDetail.getChildren(), false);
				return;
			}
			
			if (saveFlg){
				int ans = MsgBoxUtils.questionMsgBox("question.CONTINUE_WITHOUT_SAVE");
				if (ans == SWT.NO){
					btnEdit.setFocus();
					return;
				}
			}
			
			if (!Utils.isNullEmpty(this.mode) && this.mode.equals(Const.MODE_EDIT) ){
				displayReserveDetail();
			}
			
			if (!Utils.isNullEmpty(this.mode) && this.mode.equals(Const.MODE_NEW) ){
				SWTUtils.OperatorUI.clearAll(grpDetail.getChildren());
			}
			
			saveFlg = true;
			SWTUtils.OperatorUI.setEnableAll(grpDetail.getChildren(), true);
			
			// set detail
			Calendar cal = Calendar.getInstance();
			String reserveStatus = SWTUtils.ComboProcess.getSelectingValue(cmbRentStatus);
			if (reserveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_BOOKING)){
				if (Utils.isNullEmpty(txtBookYmd.getData()) && Utils.isNullEmpty(txtBookTimer.getData())){
					txtBookYmd.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
					txtBookTimer.setTime(cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
				}
				SWTUtils.OperatorUI.setEnableAll(grpDrink.getChildren(), false);
				SWTUtils.OperatorUI.setEnableAll(grpFood.getChildren(), false);
				
				Control[] grpCtrl = new Control[]{
						txtBeginYmd, txtBeginTimer, btnSync2,
						txtEndYmd, txtEndTimer, btnSync3,
						btnTotal
				};
				SWTUtils.OperatorUI.setEnableAll(grpCtrl, false);
				txtBookYmd.setFocus();
				
			} else if (reserveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_IN_USE)){
				if (Utils.isNullEmpty(txtBeginYmd.getData()) && Utils.isNullEmpty(txtBeginTimer.getData())){
					txtBeginYmd.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
					txtBeginTimer.setTime(cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
				}
				Control[] grpCtrl = new Control[]{
						txtBookYmd, txtBookYmd, btnSync1,
						txtEndYmd, txtEndTimer, btnSync3
				};
				SWTUtils.OperatorUI.setEnableAll(grpCtrl, false);
				if (!Utils.isNullEmpty(txtEndYmd.getData()) && !Utils.isNullEmpty(txtEndTimer.getData())){
					btnTotal.setEnabled(true);
				}else{
					btnTotal.setEnabled(false);
				}
				txtBeginYmd.setFocus();
				
			} else if (reserveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_FINISHED)){
				if (Utils.isNullEmpty(txtEndYmd.getData()) && Utils.isNullEmpty(txtEndTimer.getData())){
					txtEndYmd.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
					txtEndTimer.setTime(cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
				}
				Control[] grpCtrl = new Control[]{
						txtBookYmd, txtBookYmd, btnSync1,
						txtBeginYmd, txtBeginTimer, btnSync2
				};
				SWTUtils.OperatorUI.setEnableAll(grpCtrl, false);
				txtEndYmd.setFocus();
			}
			
		} catch (ClientException e) {
			log.error("ClientException.", e);
			fatalErrorMsgBox();
		}
	}

	/**
	 * check input of reserve info
	 * @return boolean
	 */
	private boolean chkInput() throws ClientException {
		
		if (!SWTUtils.Check.checkRequired(clblCusName, LangResources.getText("SWTReservationsEntry.lblCustomer"))){
			btnCustomerInput.setFocus();
			return false;
		}
				
		String selectingResereveStatus = SWTUtils.ComboProcess.getSelectingValue(cmbRentStatus);
		if (this.mode.equals(Const.MODE_NEW)) {	
			if (selectingResereveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_FINISHED)){
				MsgBoxUtils.errorMsgBox("errors.CANNOT_FINISH_WITHOUT_INUSE");
				cmbRentStatus.setFocus();
				return false;
			}
		} else if (this.mode.equals(Const.MODE_EDIT)) {	
			if (Utils.isNullEmpty(tmpReserveDto.getInuseYmd()) 
					|| Utils.isNullEmpty(tmpReserveDto.getInuseYmd())) {
				if (selectingResereveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_FINISHED)){
					MsgBoxUtils.errorMsgBox("errors.CANNOT_FINISH_WITHOUT_INUSE");
					cmbRentStatus.setFocus();
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * saveAction
	 */
	protected void saveAction() {
		
		try {
			clblMessage.setText("");
			
			if (!saveFlg){
				MsgBoxUtils.warningMsgBox("warning.NO_DATA_SAVE");
				return;
			}
			
			if (!chkSaveInput()){
				return;
			}
			
			//lock screen
			lockScreen(true);
			
			ReserveForm form = getRegistData();
			form.setActionForm("reserveForm");
			form.setActionMethod("saveAction");
			form = (ReserveForm)execute(form);
			
			//release resource
			this.tmpReserveDto = null;
			this.drinkList = null;
			this.foodList = null;
			this.mode = null;
			this.tmpCustomer = null;
			this.saveFlg = false;
			
			//unlock screen
			lockScreen(false);
			
			searchAction();
			
			MsgBoxUtils.setStatusLabelMessage(clblMessage, "info.SAVE_SUCCESSFUL");
		
		} catch (SessionTimeOutException e) {
			log.error("SessionTimeOutException.", e);
			
		} catch (FatalException e) {
			log.error("FatalException.", e);
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * chkSaveInput
	 * @return boolean
	 * @throws ClientException
	 */
	private boolean chkSaveInput() throws ClientException {

		String reserveStatus = SWTUtils.ComboProcess.getSelectingValue(cmbRentStatus);
		if (reserveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_BOOKING)){
			if (!SWTUtils.Check.checkRequired(txtBookYmd, 
					LangResources.getText("SWTReservationsEntry.lblBookTime"))){
				return false;
			}
			
			if (!SWTUtils.Check.checkRequired(txtBookYmd, 
					LangResources.getText("SWTReservationsEntry.lblBookTime"))){
				return false;
			}
			
//			if (!SWTUtils.Check.checkYYYYMMDDFormat(txtBookYmd.getText(), 
//					LangResources.getText("SWTReservationsEntry.lblBookTime"))){
//				txtBookYmd.setFocus();
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkHHMMFormat(txtBookYmd.getText(), 
//					LangResources.getText("SWTReservationsEntry.lblBookTime"))){
//				txtBookYmd.setFocus();
//				return false;
//			}
//			
//			if (!Utils.isNullEmpty(txtBeginYmd.getText()) && !Utils.isNullEmpty(txtBeginTimer.getText())){
//				if (!SWTUtils.Check.checkYYYYMMDDBiggerOrEqual(txtBeginYmd.getText(), txtBookYmd.getText(),
//						LangResources.getText("SWTReservationsEntry.lblActiveTime"),
//						LangResources.getText("SWTReservationsEntry.lblBookTime"))){
//					txtBookYmd.setFocus();
//					return false;
//				}
//				
//				if (txtBeginYmd.getText().equals(txtBookYmd.getText())){
//					if (!SWTUtils.Check.checkHHMMBiggerOrEqual(txtBeginTimer.getText(), txtBookYmd.getText(),
//							LangResources.getText("SWTReservationsEntry.lblActiveTime"),
//							LangResources.getText("SWTReservationsEntry.lblBookTime"))){
//						txtBookYmd.setFocus();
//						return false;
//					}
//				}
//			}
			
		} else if (reserveStatus.equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_IN_USE)){
			if (!SWTUtils.Check.checkRequired(txtBeginYmd, 
					LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
				return false;
			}
			
			if (!SWTUtils.Check.checkRequired(txtBeginTimer, 
					LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
				return false;
			}
			
//			if (!SWTUtils.Check.checkYYYYMMDDFormat(txtBeginYmd.getText(), 
//					LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
//				txtBeginYmd.setFocus();
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkHHMMFormat(txtBeginTimer.getText(), 
//					LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
//				txtBeginTimer.setFocus();
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkYYYYMMDDBiggerOrEqual(txtBeginYmd.getText(), txtBookYmd.getText(),
//					LangResources.getText("SWTReservationsEntry.lblActiveTime"),
//					LangResources.getText("SWTReservationsEntry.lblBookTime"))){
//				txtBeginYmd.setFocus();
//				return false;
//			}
//			
//			if (txtBeginYmd.getText().equals(txtBookYmd.getText())){
//				if (!SWTUtils.Check.checkHHMMBiggerOrEqual(txtBeginTimer.getText(), txtBookYmd.getText(),
//						LangResources.getText("SWTReservationsEntry.lblActiveTime"),
//						LangResources.getText("SWTReservationsEntry.lblBookTime"))){
//					txtBeginTimer.setFocus();
//					return false;
//				}
//			}
//			
//			if (!Utils.isNullEmpty(txtFinishYmd.getText()) && !Utils.isNullEmpty(txtFinishTimer.getText())){
//				if (!SWTUtils.Check.checkYYYYMMDDBiggerOrEqual(txtFinishYmd.getText(), txtBeginYmd.getText(),
//						LangResources.getText("SWTReservationsEntry.lblFinishTime"),
//						LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
//					txtBeginYmd.setFocus();
//					return false;
//				}
//				
//				if (txtFinishYmd.getText().trim().equals(txtBeginYmd.getText().trim())){
//					if (!SWTUtils.Check.checkHHMMBiggerOrEqual(txtFinishTimer.getText(), txtBeginTimer.getText(),
//							LangResources.getText("SWTReservationsEntry.lblFinishTime"),
//							LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
//						txtBeginTimer.setFocus();
//						return false;
//					}
//				}
//			}
			
		} else {
//			if (!SWTUtils.Check.checkRequired(txtFinishYmd, 
//					LangResources.getText("SWTReservationsEntry.lblFinishTime"))){
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkRequired(txtFinishTimer, 
//					LangResources.getText("SWTReservationsEntry.lblFinishTime"))){
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkYYYYMMDDFormat(txtFinishYmd.getText(), 
//					LangResources.getText("SWTReservationsEntry.lblFinishTime"))){
//				txtFinishYmd.setFocus();
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkHHMMFormat(txtFinishTimer.getText(), 
//					LangResources.getText("SWTReservationsEntry.lblFinishTime"))){
//				txtFinishTimer.setFocus();
//				return false;
//			}
//			
//			if (!SWTUtils.Check.checkYYYYMMDDBiggerOrEqual(txtFinishYmd.getText(), txtBeginYmd.getText(),
//					LangResources.getText("SWTReservationsEntry.lblFinishTime"),
//					LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
//				txtFinishYmd.setFocus();
//				return false;
//			}
//			
//			if (txtFinishYmd.getText().trim().equals(txtBeginYmd.getText().trim())){
//				if (!SWTUtils.Check.checkHHMMBiggerOrEqual(txtFinishTimer.getText(), txtBeginTimer.getText(),
//						LangResources.getText("SWTReservationsEntry.lblFinishTime"),
//						LangResources.getText("SWTReservationsEntry.lblActiveTime"))){
//					txtFinishTimer.setFocus();
//					return false;
//				}
//			}
		}
		
		return true;
	}

	/**
	 * getRegistData
	 * @return ReserveForm
	 */
	private ReserveForm getRegistData() {
		
		ReserveForm form = new ReserveForm();
		form.setReserveDto(tmpReserveDto);
		if (null != form){
			//food + drink
			form.setProcessMode(mode);
			form.getReserveDto().setFoodList(foodList);
			form.getReserveDto().setDrinkList(drinkList);
			//Reservation
			form.getReserveDto().setRentType(SWTUtils.ComboProcess.getSelectingValue(cmbRentType));
			form.getReserveDto().setReserveStatus(SWTUtils.ComboProcess.getSelectingValue(cmbRentStatus));
//			form.getReserveDto().setBookingYmd(Utils.toEmpty(txtBookYmd.getText()));
//			form.getReserveDto().setBookingTime(Utils.toEmpty(txtBookYmd.getText()));
//			form.getReserveDto().setInuseYmd(Utils.toEmpty(txtBeginYmd.getText()));
//			form.getReserveDto().setInuseTime(Utils.toEmpty(txtBeginTimer.getText()));
//			form.getReserveDto().setFinishYmd(Utils.toEmpty(txtFinishYmd.getText()));
//			form.getReserveDto().setFinishTime(Utils.toEmpty(txtFinishTimer.getText()));
			form.getReserveDto().setNote(Utils.toEmpty(txtNote.getText()));
			form.getReserveDto().setCurrency(SWTUtils.ComboProcess.getSelectingValue(cmbMoney));
			//Customer
			form.getReserveDto().setCustomer(tmpCustomer);
			//Bill
			if (form.getReserveDto().getReserveStatus().equals(Const.SYSTEM_CONFIG.RESERVE_STATUS_FINISHED)){
				form.setBillingFlag(true);
				BillDTO bill = new BillDTO();
//				bill.setStartYmd(Utils.toEmpty(txtBeginYmd.getText()));
//				bill.setStartTime(Utils.toEmpty(txtBeginTimer.getText()));
//				bill.setEndYmd(Utils.toEmpty(txtFinishYmd.getText()));
//				bill.setEndTime(Utils.toEmpty(txtFinishTimer.getText()));
				bill.setPayMoney(Utils.toNormalNumber(clblTotal.getText()));
				form.getReserveDto().setBill(bill);
			}
		}
		//
		return form;
	}

	/**
	 * call CustomerInput screen
	 *
	 */
	private void callCustomerInputEntry(){
		
		try {
			SWTManager.businessStart(SWTRegisterCustomerEntry.class);
			
		} catch (FatalException e) {
			fatalErrorMsgBox();
			return;
		}
	}

	/**
	 * lockScreen
	 * @param flg 
	 */
	protected void lockScreen(boolean flg) {
		
		SWTUtils.OperatorUI.setEnableAll(this.getChildren(), !flg);
	}
	
	/**
	 * createNewReservation
	 * @param room 
	 * @param openSearchRoomScreen 
	 */
	private void newAction(MstRoomDTO room, boolean openSearchRoomScreen) {
		
		try {
			tmpReserveDto = new ReserveDto();
			if (openSearchRoomScreen){
				room = SWTUtils.SWTControlProcess.openRoomSearchScreen(txtRoom);
				if (null == room){
					MsgBoxUtils.errorMsgBox("errors.SELECT_ROOM");
					txtRoom.setFocus();
					return;
				}
			}
			
			if (!room.getStatus().equals(Const.SYSTEM_CONFIG.ROOM_STATUS_FREE)
					&& !room.getStatus().equals(Const.SYSTEM_CONFIG.ROOM_STATUS_BOOKED)){
				MsgBoxUtils.errorMsgBox("errors.ROOM_STATUS_NOT_FREE_OR_BOOKED");
				txtRoom.setFocus();
				return;
			}
			tmpReserveDto.setRoom(room);
			if (room != null){
				clblRoomName.setText(room.getRoomName());
				clblRoomName.setData(room.getRoomNo());
				clblRoomType.setText(room.getRoomTypeName());
				cmbRentType.setData(room.getPriceList());
				String price = getRoomPrice(room.getPriceList(), 
						SWTUtils.ComboProcess.getSelectingValue(cmbRentType),
						SWTUtils.ComboProcess.getSelectingValue(cmbMoney));
				clblRentPrice.setText(Utils.formatDouble(price));
			}
			//
			SWTUtils.OperatorUI.setEnableAll(grpSearch.getChildren(), false);
			SWTUtils.OperatorUI.setEnableAll(grpInfo.getChildren(), true);
			SWTUtils.OperatorUI.setEnableAll(grpDetail.getChildren(), false);
			btnSave.setEnabled(true);
			btnDelete.setEnabled(false);
			clblMode.setText(Const.MODE_NEW);
			cmbRentType.setFocus();
			
			this.mode = Const.MODE_NEW;
			
		} catch (ClientException e) {
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * openRoomSearchScreen
	 * @param txt
	 */
	private void openRoomSearchScreen(Text txt){
		
		SWTUtils.SWTControlProcess.openRoomSearchScreen(txt);
		if (txt.isFocusControl()){
			txt.selectAll();
		}
	}
	
	/**
	 * openCustomerSearchScreen
	 * @param txt
	 */
	private void openCustomerSearchScreen(){
		
		MstCustomerDTO cus = SWTUtils.SWTControlProcess.openCustomerSearchScreen();
		if (null != cus){
			tmpCustomer = cus;
			clblCusName.setText(cus.getName());
			clblIdNumber.setText(cus.getIdNumber());
			clblTel.setText(cus.getTel());
		}
	}
	
	/**
	 * openDetailSearchScreen
	 * @param txt
	 * @param clblName 
	 * @param clblUnitprice 
	 * @param detail
	 */
	private void openDetailSearchScreen(Text txt, CLabel clblName, CLabel clblUnitprice, int detail){
		
		switch (detail) {
		case ReserveForm.FOOD:
			MstFoodDTO food = SWTUtils.SWTControlProcess.openFoodSearchScreen(txt, clblName);
			if (null != food){
				String currency = SWTUtils.ComboProcess.getSelectingValue(cmbMoney);
				clblUnitprice.setText(Utils.formatDouble(getDetailPrice(food.getPriceList(), currency)));
			}
			break;

		default:
			break;
		}
		
		if (txt.isFocusControl()){
			txt.selectAll();
		}
	}
	
	/**
	 * getDetailPrice
	 * @param priceList
	 * @param currency
	 * @return String
	 */
	private String getDetailPrice(ArrayList priceList, String currency) {
		
		for (int i = 0; i < priceList.size(); i++) {
			MstPriceDTO price = (MstPriceDTO)priceList.get(i);
			if (price.getMoneyType().equals(currency)){
				return price.getPrice();
			}
		}
		return "";
	}

	/**
	 * editSelectingDetail
	 * @param table
	 * @param detail
	 */
	private void editSelectingDetail(Table table, int detail){
		
		TableItem item = table.getItem(table.getSelectionIndex());
		ReserveDetailDTO det = (ReserveDetailDTO)item.getData();
		if (null == det){
			return;
		}
		
		switch (detail) {
		case ReserveForm.DRINK:
			txtDrinkNo.setText(det.getDetailNo());
			clblDrinkName.setText(det.getDetailname());
			clblDrinkUnitPrice.setText(Utils.formatDouble(det.getUnitPrice()));
			txtDrinkQty.setText(det.getQuantity());
			txtDrinkQty.setFocus();
			break;

		case ReserveForm.FOOD:
			txtFoodNo.setText(det.getDetailNo());
			clblFoodName.setText(det.getDetailname());
			clblFoodUnitPrice.setText(Utils.formatDouble(det.getUnitPrice()));
			txtFoodQty.setText(det.getQuantity());
			txtFoodQty.setFocus();
			break;
		default:
			break;
		}
	}
	
	/**
	 * detailNoLostFocus
	 * @param txtNo
	 * @param clblName
	 * @param clblUnitPrice
	 * @param detail
	 */
	private void detailNoLostFocus(Text txtNo, CLabel clblName,
			CLabel clblUnitPrice, int detail) {

		switch (detail) {
		case ReserveForm.DRINK:
			MstDrinkDTO drink = SWTUtils.SWTControlProcess.textDrinkNoLostFocusAction(txtNo, clblName);
			if (null != drink){
				String currency = SWTUtils.ComboProcess.getSelectingValue(cmbMoney);
				clblUnitPrice.setText(Utils.formatDouble(getDetailPrice(drink.getPriceList(), currency)));
			} else {
				clblName.setText("");
				clblUnitPrice.setText("");
			}
			break;
			
		case ReserveForm.FOOD:
			MstFoodDTO food = SWTUtils.SWTControlProcess.textFoodNoLostFocusAction(txtNo, clblName);
			if (null != food){
				String currency = SWTUtils.ComboProcess.getSelectingValue(cmbMoney);
				clblUnitPrice.setText(Utils.formatDouble(getDetailPrice(food.getPriceList(), currency)));
			} else {
				clblName.setText("");
				clblUnitPrice.setText("");
			}
			break;

		default:
			break;
		}
	}
	
	/**
	 * addFoodDetail
	 *
	 */
	@SuppressWarnings("unchecked")
	private void addFoodDetail(){
		
		try {
			if (!SWTUtils.Check.checkRequired(txtFoodNo, 
					LangResources.getText("SWTReservationsEntry.tblFood.tcolFood"))){
				return;
			}
			if (!SWTUtils.Check.checkNumeric(txtFoodNo, 
					LangResources.getText("SWTReservationsEntry.tblFood.tcolFood"))){
				return;
			}
			if (!SWTUtils.Check.checkRequired(txtFoodQty, 
					LangResources.getText("SWTReservationsEntry.tblFood.tcolFoodQty"))){
				return;
			}
			if (!SWTUtils.Check.checkNumeric(txtFoodQty, 
					LangResources.getText("SWTReservationsEntry.tblFood.tcolFoodQty"))){
				return;
			}
			
			String modeprocess = "";
			ReserveDetailDTO det = null;
			int idx = chkExistOfDetail(txtFoodNo.getText().trim(), foodList);
			if (idx == -1){
				modeprocess = Const.MODE_NEW;
			}else{
				TableItem item = tblFood.getItem(idx);
				det = (ReserveDetailDTO)item.getData();
				if (null == det){
					modeprocess = Const.MODE_NEW;
				}
			}
			
			if (modeprocess.equals(Const.MODE_NEW)){
				det = new ReserveDetailDTO();
			}
			
			det.setDetailNo(txtFoodNo.getText());
			det.setDetailname(clblFoodName.getText());
			String unitprice = Utils.toNormalNumber(clblFoodUnitPrice.getText());
			String qty = txtFoodQty.getText();
			String price = String.valueOf(Double.parseDouble(unitprice) * Integer.parseInt(qty));
			det.setUnitPrice(unitprice);
			det.setQuantity(qty);
			det.setPrice(price);
			
			if (modeprocess.equals(Const.MODE_NEW)){
				foodList.add(det);
			}else{
				foodList.set(idx, det);
			}
			
			displayTableDetail(tblFood, foodList, clblFoodTotal);
			
			Control[] controls = new Control[]{
					txtFoodNo, clblFoodName, 
					clblFoodUnitPrice, txtFoodQty
			};
			SWTUtils.OperatorUI.clearAll(controls);
			if (idx >= 0){
				tblFood.setSelection(idx);
			}else{
				tblFood.setSelection(foodList.size()-1);
			}
			tblFood.setFocus();
			
		} catch (ClientException e) {
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * addDrinkDetail
	 *
	 */
	@SuppressWarnings("unchecked")
	private void addDrinkDetail(){
		
		try {
			if (!SWTUtils.Check.checkRequired(txtDrinkNo, 
					LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrink"))){
				return;
			}
			if (!SWTUtils.Check.checkNumeric(txtDrinkNo, 
					LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrink"))){
				return;
			}
			if (!SWTUtils.Check.checkRequired(txtDrinkQty, 
					LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrinkQty"))){
				return;
			}
			if (!SWTUtils.Check.checkNumeric(txtDrinkQty, 
					LangResources.getText("SWTReservationsEntry.tblDrink.tcolDrinkQty"))){
				return;
			}
			
			String modeprocess = "";
			ReserveDetailDTO det = null;
			int idx = chkExistOfDetail(txtDrinkNo.getText().trim(), drinkList);
			if (idx == -1){
				modeprocess = Const.MODE_NEW;
			}else{
				TableItem item = tblDrink.getItem(idx);
				det = (ReserveDetailDTO)item.getData();
				if (null == det){
					modeprocess = Const.MODE_NEW;
				}
			}
			
			if (modeprocess.equals(Const.MODE_NEW)){
				det = new ReserveDetailDTO();
			}
			
			det.setDetailNo(txtDrinkNo.getText());
			det.setDetailname(clblDrinkName.getText());
			String unitprice = Utils.toNormalNumber(clblDrinkUnitPrice.getText());
			String qty = txtDrinkQty.getText();
			String price = String.valueOf(Double.parseDouble(unitprice) * Integer.parseInt(qty));
			det.setUnitPrice(unitprice);
			det.setQuantity(qty);
			det.setPrice(price);
			
			if (modeprocess.equals(Const.MODE_NEW)){
				drinkList.add(det);
			}else{
				drinkList.set(idx, det);
			}
			
			displayTableDetail(tblDrink, drinkList, clblDrinkTotal);
			
			Control[] controls = new Control[]{
					txtDrinkNo, clblDrinkName, 
					clblDrinkUnitPrice, txtDrinkQty
			};
			SWTUtils.OperatorUI.clearAll(controls);
			if (idx >= 0){
				tblDrink.setSelection(idx);
			}else{
				tblDrink.setSelection(drinkList.size()-1);
			}
			tblDrink.setFocus();
			
		} catch (ClientException e) {
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * txtFinishTimer
	 * @param no
	 * @param list
	 * @return int
	 */
	private int chkExistOfDetail(String no, ArrayList list) {
		
		for (int i = 0; i < list.size(); i++) {
			ReserveDetailDTO det = (ReserveDetailDTO)list.get(i);
			if (no.equals(det.getDetailNo())){
				return i;
			}
		}
		return -1;
	}

	/**
	 * removeFoodDetail
	 *
	 */
	private void removeDetail(Table table, int detail ){
		
		try {
			int idx = table.getSelectionIndex();
			if (idx == -1) {
				MsgBoxUtils.errorMsgBox("errors.NOT_SELECTED_RECORD", new Object[]{});
				switch (detail) {
				case ReserveForm.DRINK:
					btnDrinkRemove.setFocus();
					break;

				case ReserveForm.FOOD:
					btnFoodRemove.setFocus();
					break;
				}
				return;
			}
			
			TableItem row = table.getItem(idx);
			ReserveDetailDTO det = (ReserveDetailDTO)row.getData();
			if (null == det){
				MsgBoxUtils.errorMsgBox("errors.NOT_SELECTED_RECORD", new Object[]{});
				switch (detail) {
				case ReserveForm.DRINK:
					btnDrinkRemove.setFocus();
					break;

				case ReserveForm.FOOD:
					btnFoodRemove.setFocus();
					break;
				}
				return;
			}
			
			switch (detail) {
			case ReserveForm.DRINK:
				drinkList.remove(idx);
				displayTableDetail(table, drinkList, clblDrinkTotal);
				break;

			case ReserveForm.FOOD:
				foodList.remove(idx);
				displayTableDetail(table, foodList, clblFoodTotal);
				break;
			}
			
			table.setFocus();
			
		} catch (ClientException e) {
			log.error("ClientException.", e);
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * calTotalPrice
	 *
	 */
	private void calTotalPrice() {
		
		try {
			if (!chkSaveInput()){
				return;
			}
			
			getRegistData();
			
			double total = 0;
			double roomtotal = 0;
			double othertotal = 0;
			String rentType = SWTUtils.ComboProcess.getSelectingValue(cmbRentType);
			
			roomtotal = SWTUtils.SWTControlProcess.calRoomTotalMoney(tmpReserveDto, clblRentPrice.getText());
			othertotal = calOthersTotalMoney(rentType);
			total = roomtotal + othertotal;
			
			clblTotal.setText(Utils.formatDouble(String.valueOf(Utils.round(total, 1))));
			clblRoomTotal.setText(Utils.formatDouble(String.valueOf(Utils.round(roomtotal, 1))));
			clblOtherTotal.setText(Utils.formatDouble(String.valueOf(Utils.round(othertotal, 1))));
			
		} catch (ClientException e) {
			fatalErrorMsgBox();
		}
	}
	
	/**
	 * calOthersTotalMoney
	 * @param rentType
	 * @return double
	 */
	private double calOthersTotalMoney(String rentType) {
		
		double total = 0;
		total = Double.parseDouble(Utils.toNormalNumber(clblFoodTotal.getText()))
				+ Double.parseDouble(Utils.toNormalNumber(clblDrinkTotal.getText()));

		return total;
	}

	/**
	 * getRoom
	 * @return MstRoomDTO
	 */
	private MstRoomDTO getRoom() {
		
		MstRoomDTO room = null;
		try {
			CommonSearchForm form = new CommonSearchForm();
			form.setActionForm("commonSearchForm");
			form.setActionMethod("getRoomList");
			form.setSearchName(Utils.toEmpty(txtRoom.getText()));
			
			form = (CommonSearchForm)execute(form);
			
			ArrayList roomList = form.getList();
			if (roomList.size() > 1){
				room = SWTUtils.SWTControlProcess.openRoomSearchScreen(txtRoom, true);
				
			}else if (roomList != null && roomList.size() == 1){
				room = (MstRoomDTO)roomList.get(0);
			}
			
		} catch (SessionTimeOutException e) {
			log.error("SessionTimeOutException.", e);
			
		} catch (FatalException e) {
			log.error("FatalException.", e);
			fatalErrorMsgBox();
		}
		
		return room;
	}

	@Override
	protected boolean loadData() throws FatalException {
		// TODO Auto-generated method stub
		return false;
	}
}